package com.szh.zx.duoxiancheng.asynctask;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Timer死循环
 * */
public class EndlessLoopTimer {
    static class LoopTask extends TimerTask{

        @Override
        public void run() {
            while (true){
                try {
                    // 模拟执行任务
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    // 永远没有机会执行
    static class ExampleTask extends TimerTask{

        @Override
        public void run() {
            System.out.println("hello");
        }
    }


    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new LoopTask(),10);
        timer.schedule(new ExampleTask(), 100);

    }
}
